﻿using Microsoft.EntityFrameworkCore;
using PhoneServer.Models;

namespace PhoneServer.Contexts
{
    /// <summary>
    ///  1、数据库上下文
    /// </summary>
    

    public class MobilePhoneContext : DbContext
    {
        DbSet<Brand> brands { get; set; }
        DbSet<Inventory> inventories { get; set; }
        DbSet<MobilePhone> mobilePhones { get; set; }
        DbSet<Model> models { get; set; }
        DbSet<ModelDetails> modelDetails { get; set; }
        DbSet<PurchaseOrder> purchaseOrders { get; set; }
        DbSet<SalesOrder> salesOrders { get; set; }
        DbSet<Supplier> suppliers { get; set; }
        DbSet<Withdrawal> Withdrawals { get; set; }

        public MobilePhoneContext(DbContextOptions options) : base(options)
        {
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Inventory>()
               .Property(i => i.PriceChange)
               .HasColumnType("decimal(18,2)");

            modelBuilder.Entity<PurchaseOrder>()
               .Property(i => i.PurchasePrice)
               .HasColumnType("decimal(18,2)");

            modelBuilder.Entity<Withdrawal>()
                .Property(i => i.Amount)
                .HasColumnType("decimal(18,2)");
        }


    }
}
